﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace LFSRecord2.Model.Sound
{
    public class WaveBitmap
    {
        int _bpp = 4;
        int t;

        public int Width { get; private set; }
        public int Height { get; private set; }
        public int Stride { get; private set; }
        public byte[] BitmapData { get; private set; }

        public WaveBitmap(int width, int height)
        {
            Width = width;
            Height = height;
            Stride = width * _bpp;
            BitmapData = new byte[Width * Height * _bpp];
        }

        public void setPixel(int x, int y)
        {
            t = x * _bpp + (y * Stride);
            BitmapData[t++] = 10;
            BitmapData[t++] = 128;
            BitmapData[t++] = 255;
            BitmapData[t] = 255;
        }

        public void setVLine(int x, int fromY, int toY)
        {
            int d = toY - fromY;
            setPixel(x, fromY);
            for (int a = 1; a < d; a++)
            {
                setPixel(x, fromY + a);
            }
        }

        public BitmapSource CreateBitmapSource()
        {
            return BitmapSource.Create(Width, Height, 96, 96, PixelFormats.Bgra32, null, BitmapData, Width * _bpp);
        }
    }
}
